package im.oen.boot.common.data;

import im.oen.boot.common.constant.OenCode;

/**
 * 带Code的结果数据
 *
 * @author Kevin.Xu
 */
public class Result<T> extends Base {

    private Code code;
    private T data;

    public Result() {
    }

    public Result(T data) {
        this.data = data;
    }

    public Result(Code code, T data) {
        this.code = code;
        this.data = data;
    }

    public Code getCode() {
        return code;
    }

    public void setCode(Code code) {
        this.code = code;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public static Result of(Code code) {
        return new Result(code, null);
    }

    public static <T> Result<T> of(T data) {
        return new Result<>(OenCode.SUCCESS, data);
    }

    public static <T> Result<T> of(Code code, T data) {
        return new Result<>(code, data);
    }

    public static Result SUCCESS() {
        return Result.of(OenCode.SUCCESS);
    }

    public static Result ERROR() {
        return Result.of(OenCode.SERVER_ERROR);
    }
}
